package com.bean;

import com.annotation.NumberLimit;

/**
 * @author Cc
 * 2024-04-02
 */
public class Calc {
    @NumberLimit(100)
    public int getSum(int n) throws NoSuchMethodException {
        NumberLimit annotation = this.getClass().getDeclaredMethod("getSum", int.class).getAnnotation(NumberLimit.class);

        int value = annotation.value();

        if (n <= value) {
            int result = 0;
            for (int i = 1; i <= n; i++) {
                result += i;
            }
            return result;
        }
        throw new RuntimeException("值过大");
    }
}
